package com.ccsu.joysport.controller;


import com.ccsu.joysport.util.JwtUtil;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;

@RestController
@RequestMapping("/ccsu/user")
public class LoginController {

    @Autowired
    private JwtUtil jwtUtil;
//收到token 验证token是否有效
    @PostMapping("/login")

    public ResponseEntity<?> login(@RequestBody String token) {

        try {
            if (jwtUtil.validateToken(token)) {
                return ResponseEntity.ok("Login successful");
            } else {
                return ResponseEntity.status(401).body("Invalid token");
            }
        } catch (Exception e) {
            return ResponseEntity.status(500).body("Internal Server Error");
        }
    }

}
